<template>
  <div class="app-main-container">
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        label="标题"
        prop="title"
        min-width="300"
        max-height="200"
      >
        <template slot-scope="scope">
          <el-popover
            placement="top-start"
            width="300"
            trigger="hover"
            :content="scope.row.title"
          >
            <div slot="reference" class="single-maxheight">{{ scope.row.title }}</div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="内容"
        prop="content"
        min-width="200"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="发布人员"
        prop="publishName"
        min-width="120"
      />
      <el-table-column
        align="center"
        label="发布时间"
        prop="publishTime"
        min-width="150"
      />
      <el-table-column label="状态" prop="sort" min-width="100" align="center">
        <template slot-scope="scope">
          {{ scope.row.status === "1" ? "已读" : "未读" }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        min-width="160"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <div class="flex-cc">
            <el-button
              v-if="meta.indexOf('NoticeDetail') > -1"
              v-preventReClick
              type="text"
              @click="toDetail(scope.row.id)"
            >查看详情</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- <div class="flex-cc doumee-pagination">
      <el-pagination
        hide-on-single-page
        background
        layout="prev, pager, next"
        :current-page.sync="current"
        :total="total"
        @current-change="currentChange"
      />
    </div> -->
    <Pagination
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { noticeList } from '@/api'
import { parseTime } from '@/utils/index'
import Pagination from '@/components/paginations'
import QueryForm from '@/components/QueryForm'
export default {
  name: 'NoticeList',
  components: {
    QueryForm,
    Pagination
  },
  data() {
    return {
      queryFormConfig: {
        formItems: [{
          filed: 'name',
          type: 'input',
          label: '标题',
          placeholder: '请输入标题',
          clearable: true
        }],
        online: true
      },
      list: [],
      meta: [],
      listLoading: true,
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      filters: {}
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList(1)
  },
  activated() {
    this.$refs.table.doLayout()
  },
  methods: {
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    // 获取列表
    getList(page) {
      const { pagination, filters } = this
      const venueId = sessionStorage.getItem('venueId')
      if (page) {
        this.pagination.page = page
        pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      this.listLoading = true
      noticeList({ pagination, param: { venueId, ...filters }})
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.list = res.recordList
          this.total = res.totalCount
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    toDetail(id) {
      // console.log(id)
      this.$router.push({
        name: 'NoticeDetail',
        query: {
          id
        }
      })
    },
    // 清空
    clear() {
      this.filters = {}
      this.getList(1)
    }
  }
}
</script>

<style lang="scss" scoped>
.tableClass .cell {
  padding: 0 !important;
  height: 40px;
  line-height: 30px !important;
  text-align: center;
}

</style>
